#include <iostream>
#include <string>
using namespace std;

struct node {
	node *l, *r;
	char ch;
};

node *tree;

node *insert(node *p, char ch) {
	if (p == NULL) {
		node *q = new node;
		q->ch = ch;
		q->l = q->r = NULL;
		return q;
	} else {
		if(ch < p->ch) p->l = insert(p->l, ch);
		else p->r = insert(p->r, ch);
		return p;
	}
}

node *init(node *p) {
	if (p == NULL) return NULL;
	p->l = init(p->l);
	p->r = init(p->r);
	p = NULL;
	return p;
}

void print(node *p) {
	if(p == NULL)return;
	cout << p->ch; 
	print(p->l);
	print(p->r);
}

int sum;
string ch[105];

int main() {
	while (1) {
		
		cin >> ch[++sum];
		if (ch[sum][0] == '*' || ch[sum][0] == '$') {
			--sum;
			for (int i = sum; i >= 1; --i) {
				for (int j = 0; j < ch[i].size(); ++j) {
					tree = insert(tree, ch[i][j]);
				} 
			}
			print(tree);
			cout << endl;
			tree = init(tree);
			if (ch[sum+1][0] == '$') break;
			sum = 0;
		}
	}
	return 0;
}
